<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        ul {
            list-style: none;
        }
        li {
            width: 50px;
            background-color: #3399ff;
            text-align: center;
            cursor: pointer;
            margin: auto;
        }
        li:nth-child(2n){
            background-color: cyan;
        }
    </style>
</head>
<body>
    <ul>
        <li>a</li>
        <li>a</li>
        <li>a</li>
        <li>a</li>
    </ul>

    <script>

        var li = document.getElementsByTagName('li');
        for(var i = 0; i < li.length; i ++){
            (function(i){
                li[i].addEventListener('click', function(){
                    console.log(i + 1);
                }, false);
            }(i))
        }


    </script>
</body>
</html>